create_data/0. get_ISCO_hierarchy.R

library(httr)
library(jsonlite)
library(tidyverse)
library(parallel)

two_digit_code_tbl <- tibble(.rows = NULL)
three_digit_code_tbl <- tibble(.rows = NULL)
four_digit_code_tbl <- tibble(.rows = NULL)

# Querying two digit codes from main categories
for (code in 0:9) {

  # Defining the URL
  url <- paste0("https://ec.europa.eu/esco/api/resource/occupation?uris=http://data.europa.eu/esco/isco/C",
                code)
  # Calling API
  response <- fromJSON(txt=url(url))

  # Getting child concepts
  two_digit_codes <- response$`_embedded`[[1]]$`_links`$narrowerConcept
  # Concatenating
  two_digit_code_tbl <- bind_rows(two_digit_code_tbl, two_digit_codes)
}

two_digit_code_tbl <- two_digit_code_tbl %>%
  mutate(title_it = "")

for (code in two_digit_code_tbl$code) {

  url <- paste0("https://ec.europa.eu/esco/api/resource/occupation?uris=http://data.europa.eu/esco/isco/C",
                code)
  response <- fromJSON(txt=url(url))

  # Getting the translated labels for two digit codes
  label_en <- response$`_embedded`[[1]]$preferredTerm$en$label
  label_it <- response$`_embedded`[[1]]$preferredTerm$it$label
  row <- match(code, two_digit_code_tbl$code)
  two_digit_code_tbl$title_it[row] <- label_it

  three_digit_codes <- response$`_embedded`[[1]]$`_links`$narrowerConcept
  three_digit_code_tbl <- bind_rows(three_digit_code_tbl, three_digit_codes)

}

three_digit_code_tbl <- three_digit_code_tbl %>%
  mutate(title_it = "")

for (code in three_digit_code_tbl$code) {

  url <- paste0("https://ec.europa.eu/esco/api/resource/occupation?uris=http://data.europa.eu/esco/isco/C",
                code)
  response <- fromJSON(txt=url(url))

  # Getting the translated labels for two digit codes
  label_en <- response$`_embedded`[[1]]$preferredTerm$en$label
  label_it <- response$`_embedded`[[1]]$preferredTerm$it$label
  row <- match(code, three_digit_code_tbl$code)
  three_digit_code_tbl$title_it[row] <- label_it

  four_digit_codes <- response$`_embedded`[[1]]$`_links`$narrowerConcept
  four_digit_code_tbl <- bind_rows(four_digit_code_tbl, four_digit_codes)

}

four_digit_code_tbl <- four_digit_code_tbl %>%
  mutate(title_it = "")

for (code in four_digit_code_tbl$code) {

  url <- paste0("https://ec.europa.eu/esco/api/resource/occupation?uris=http://data.europa.eu/esco/isco/C",
                code)
  response <- fromJSON(txt=url(url))

  # Getting the translated labels for two digit codes
  label_en <- response$`_embedded`[[1]]$preferredTerm$en$label
  label_it <- response$`_embedded`[[1]]$preferredTerm$it$label
  row <- match(code, four_digit_code_tbl$code)
  four_digit_code_tbl$title_it[row] <- label_it

}


ISCO_structure <- bind_rows(two_digit_code_tbl, three_digit_code_tbl, four_digit_code_tbl)

saveRDS(object = ISCO_structure, file = "create_data/ISCO_structure.rds")
ldbolanos/standards documentation built on Aug. 7, 2020, 8:13 p.m.